﻿using System.Linq;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;
namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// Credit Card Type Repository
    /// </summary>
    public class CreditCardTypeRepository : ICreditCardTypeRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get Credit Card Type Details by Title
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<CreditCardType> FindCreditCardTypeByName(string strQuery)
        {
            return _db.CreditCardTypes.Where(d => d.CreditCardTypeName.Contains(strQuery));
        }

        /// <summary>
        /// Get All Credit Card Type
        /// </summary>
        /// <returns></returns>
        public IQueryable<CreditCardType> FindAllCreditCardType()
        {
            return _db.CreditCardTypes;
        }

        /// <summary>
        /// Get Credit Card Type by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public CreditCardType GetCreditCardTypeById(int id)
        {
            return _db.CreditCardTypes.SingleOrDefault(d => d.CreditCardTypeId == id);
        }

        /// <summary>
        /// Add Credit Card Type in the Database
        /// </summary>
        /// <param name="creditCardType"></param>
        public void Add(CreditCardType creditCardType)
        {
            _db.CreditCardTypes.AddObject(creditCardType);
        }

        /// <summary>
        /// Delete Credit Card Type from Database
        /// </summary>
        /// <param name="creditCardType"></param>
        public void Delete(CreditCardType creditCardType)
        {
            _db.CreditCardTypes.DeleteObject(creditCardType);
        }

        /// <summary>
        /// Save Credit Card Type in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }
    }
}